package com.yy.micro.magic.core.loader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;
 /**
   * @author YY
   * @version 1.0.0
   * @update 2021/9/22 9:29 下午
   * @description: Spring的ApplicationRunner，用于在服务启动后加载静态资源。{@link ResourceLoader#load()}
 */
@Component
public class ResourceLoaderRunner implements ApplicationRunner {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private List<ResourceLoader> loaders;
    @Override
    public void run(final ApplicationArguments args) throws Exception {
        if (null != loaders){
            for(ResourceLoader loader : loaders){
                try {
                    loader.load();
                }catch (Exception e){
                    logger.warn("loader["+loader.getClass()+"] load exception!",e);
                }
            }
        }
    }
}
